package com.xijia.wuyouwallet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.bean.DitchData;

import java.util.List;

/**
 * Created by Administrator on 2017/11/7 0007.
 */

public class DitchAdapter extends BaseAdapter {

    private List<DitchData.DataBean.ListBean> list;
    private Context context;

    public DitchAdapter(List<DitchData.DataBean.ListBean> list,Context context){
        this.list = list;
        this.context =context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view==null){
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_ditch,null);
            holder.itemDitch_title = (TextView) view.findViewById(R.id.itemDitch_title);
            holder.itemDitch_quota = (TextView) view.findViewById(R.id.itemDitch_quota);
            holder.itemDitch_rate = (TextView) view.findViewById(R.id.itemDitch_rate);
            holder.itemDitch_hit = (TextView) view.findViewById(R.id.itemDitch_hit);
            holder.itemDitch_icon = (ImageView) view.findViewById(R.id.itemDitch_icon);
            view.setTag(holder);
        }else {
           holder = (ViewHolder) view.getTag();
        }
        holder.itemDitch_title.setText(list.get(i).getCt_name());
        holder.itemDitch_quota.setText("额度："+list.get(i).getQuota());
        String rate = "";
        if (list.get(i).getChannel_rate()!=null){
            for (int l = 0;l<list.get(i).getChannel_rate().size();l++){
                rate = rate + list.get(i).getChannel_rate().get(l)+",";
            }
        }
        holder.itemDitch_rate.setText("费率："+rate);
        holder.itemDitch_hit.setText("提示："+list.get(i).getCt_des());
        Picasso.with(context).load(list.get(i).getCt_img()).into(holder.itemDitch_icon);
        return view;
    }

    private class ViewHolder{
        TextView itemDitch_title,itemDitch_quota,itemDitch_rate,itemDitch_hit;
        ImageView itemDitch_icon;
    }

}
